<?php

class fop_FunctionController extends Zend_Controller_Action
{
  function init() {
  	header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
	header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
    $this->getHelper('viewRenderer')->setNoRender();
  }

  function createAction() {
    require_once('fop/objects/function.php');
    try{
	  $results = fop_Object_Function::create($this->_getAllParams());
    } catch(fop_Object_Exception $e) {
      $data['status'] = 	'KO';
      $data['error']['num'] = 	$e->getCode();
      $data['error']['message'] = 	$e->getMessage();
      echo Zend_Registry::get('dt_serializer')->serialize($data);	
      return;
    }
	$data['status'] = 	'OK';
	echo Zend_Registry::get('dt_serializer')->serialize($data);;
    return;
  }
  
  
  function getAction() {
    require_once('fop/objects/function.php');
    try {
      $function = new fop_Object_Function($this->_getParam('id'));
      $resFunction = $function->asArray();
    } catch(fop_Object_Exception $e) {
      $data['status'] = 	'KO';
      $data['error']['num'] = 	$e->getCode();
      $data['error']['message'] = 	$e->getMessage();
    echo Zend_Registry::get('dt_serializer')->serialize($data);	
      return;
    }
    
    //We list the different actions of the controller
    //require_once('fop/objects/controller.php');
    //$resControllers = fop_Object_Controller::listing($module->getName());
    
	$data['status'] = 	'OK';
	$data['function'] = $resFunction;
	
    echo Zend_Registry::get('dt_serializer')->serialize($data);	
    return;  	
  }


  function listAction() {
    require_once('fop/objects/function.php');
    try {
      $functionsArray = fop_Object_Function::listing();
    } catch(fop_Object_Exception $e) {
      $data['status'] = 	'KO';
      $data['error']['num'] = 	$e->getCode();
      $data['error']['message'] = 	$e->getMessage();
    echo Zend_Registry::get('dt_serializer')->serialize($data);	
      return;
    }
    
    //We list the different actions of the controller
    //require_once('fop/objects/controller.php');
    //$resControllers = fop_Object_Controller::listing($module->getName());
    
	$data['status'] = 	'OK';
	$data['functions'] = $functionsArray;
	
    echo Zend_Registry::get('dt_serializer')->serialize($data);	
    return;  	
  }  
	

} //End class


?>